Make file size messages human-readable#803
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the File validation rule to render size-related placeholders ({limit}, {exactly}) as human-readable values (e.g. 50 MB) instead of raw byte counts, and aligns defaults, tests, and documentation with that behavior.
Changes:
- Format
{limit}/{exactly}placeholders as human-readable sizes inFileHandler. - Update default
Filesize messages to use{limit}/{exactly}directly (no ICU number/plural formatting). - Add regression tests and document the new placeholder behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/Rule/FileHandler.php |
Formats size placeholders before they’re passed into error message parameters. |
src/Rule/File.php |
Updates default size messages and placeholder documentation to reflect human-readable sizing. |
tests/Rule/FileTest.php |
Adds/updates regression cases asserting new human-readable size output. |
docs/guide/en/built-in-rules-file.md |
Documents that size placeholders are now human-readable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4700917 to
3dfc85b
Compare
79319f6 to
b4e4c86
Compare
53fb650 to
7d12a71
Compare
7d12a71 to
f93aa4a
Compare
| ## 2.6.1 under development | ||
|
|
||
| - no changes in this release. | ||
| - Bug #802: Use translatable human-readable file sizes in `File` validation messages and add numeric, unit, and raw byte placeholders (@samdark) |
There was a problem hiding this comment.
| - Bug #802: Use translatable human-readable file sizes in `File` validation messages and add numeric, unit, and raw byte placeholders (@samdark) | |
| - Chg #802: Use translatable human-readable file sizes in `File` validation messages and add numeric, unit, and raw byte placeholders (@samdark) |
| } | ||
|
|
||
| return match ($unit) { | ||
| 'byte' => 'The size of {property} must be exactly {exactlyValue, number} ' |
There was a problem hiding this comment.
Add new variable {prettyExactly} and use it as default message in rule "The size of {property} must be exactly {prettyExactly}". Then insert the appropriate value in the handler.
This approach simplify code (not need constants with array of messages).
Even better use pretty value for {exactly} and create new {exactlyHuman}. So, it will be:
{exactly}- pretty value{exactlyHuman}- expected exact size as a human-readable string.{exactlyValue}: expected exact size numeric value converted to a human-readable unit.{exactlyUnit}: expected exact size unit identifier. Possible values arebyte,KB,MB,GB,TB,PB.{exactlyBytes}: expected exact size in bytes.
The same is true for new "limit" variables.
Resolves #802.
Summary
Tests
Full vendor/bin/phpunit was also run; it fails only on existing EmailTest DNS-dependent cases for gmail.com and ñandu.cl domains in this environment.